package chapter4;

import java.time.LocalDate;

public class EmployeeTest {
    public static void main(String[] args) {
        Employee[] staff = new Employee[3];
        staff[0] = new Employee("Carl",75000,1987,12,15);
        staff[1] = new Employee("Harry",50000,1989,10,1);
        staff[2] = new Employee("Tony",40000,1990,3,15);
        for (Employee e:staff){
            e.raiseSalary(5);
        }
        for (Employee e:staff) {
            System.out.println("name=" + e.getName() + ",salary=" + e.getSalary() + ",hireDay=" + e.getHireDay());
        }
        for (Employee e:staff){
            System.out.println(e.getName());
        }
        System.out.println(staff[0].equals(staff[1]));
    }

}
class Employee{
    private String name ;
    private double salary;
    private LocalDate hireDay;
    private static int nextID = 1;//属于类而不属于对象，其他的属于对象
    private int id;

    public Employee(String n,double s,int year,int month,int day){
        name = n;
        salary = s;
        hireDay = LocalDate.of(year,month,day);
    }
    public int getId(){
        return id;
    }
    public String getName(){
        return name;
    }
    public double getSalary(){
        return salary;
    }
    public LocalDate getHireDay(){
        return hireDay;
    }
    public void raiseSalary(int rate){
        salary = salary * (1+rate/100.0);
    }
    public boolean equals(Employee the_other){
        return name.equals(the_other.name);
    }
    public static int getNextID(){//静态方法,属于类，可以通过类来访问，而非对象（对象可以访问）
        return nextID;
    }
}